﻿@model CMSApplication.Areas.Administration.Models.WorkModel
@{
    ViewBag.Title = "CS Cong viec";
}
<script>
    function UpdCustomerInfo(_data) {
        if (_data != null) {
            $("#AssignCustomer").val(_data.Id);
            $("#customer-id").text(_data.Id);
            $("#customer-name").text(_data.Name);
            $("#customer-addr").text(_data.Addr);
            $("#customer-phone").text(_data.Phone);
            $(".has-not-customer").fadeOut();
            $(".has-customer").fadeIn();
        } else {
            $("#AssignCustomer").val(0);
            $(".has-customer").fadeOut();
            $(".has-not-customer").fadeIn();
        }
    };

    function xk_Fancy_onStart_Search(e) {
        Ajax({
            url: "/Work/Customer_Popup_Index",
            ExecSuccess: function (result) {
                $("#customer-search").html(result.dataServer);
                ExecForSearch({});
            }
        });
    };

    function xk_Fancy_onComplete_Search(e) {
        setTimeout(function () { FixCSSFancybox210({}); }, 500);
    };

    function xk_Fancy_onStart_Add(e) {
        Ajax({
            url: "/Work/Customer_Popup_Add",
            ExecSuccess: function (result) {
                $("#customer-new").html(result.dataServer);
            }
        });
    };

    function xk_Fancy_onComplete_Add(e) {
        setTimeout(function () { FixCSSFancybox210({}); }, 500);
    };

    jQuery(document).ready(function ($) {
        $("a[rel=search]").fancybox({
            'width': '100%',
            'height': '100%',
            'apacity': true,
            'autoScale': true,
            'autoSize': true,
            'overlayShow': true,
            'transitionIn': 'elastic', // elastic | none
            'transitionOut': 'elastic', // elastic | none
            'type': 'inline',
            'beforeLoad': function (e) { xk_Fancy_onStart_Search(e); }, // onStart | beforeLoad
            'onReady': function (e) { xk_Fancy_onComplete_Search(e); }, // onComplete | onReady
            'titlePosition': 'over',
            // 'titleFormat': function (title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; }
        });

        $("a[rel=new]").fancybox({
            'width': '100%',
            'height': '100%',
            'apacity': true,
            'autoScale': true,
            'autoSize': true,
            'overlayShow': true,
            'scrolling': true,
            'transitionIn': 'elastic', // elastic | none
            'transitionOut': 'elastic', // elastic | none
            'type': 'inline',
            'beforeLoad': function (e) { xk_Fancy_onStart_Add(e); }, // onStart | beforeLoad
            'onReady': function (e) { xk_Fancy_onComplete_Add(e); }, // onComplete | onReady
            'titlePosition': 'over',
            // 'titleFormat': function (title, currentArray, currentIndex, currentOpts) { return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; }
        });

        $("[data-id='remove']").click(function (e) {
            UpdCustomerInfo(null);
        });

        $("[data-id='save-new']").click(function (e) {
            $("#IsContinue").val(true);
            $("#validation").trigger("submit");
        });

        if ($("#AssignCustomer").val() != "" && parseInt($("#AssignCustomer").val()) > 0) {
            Ajax({
                url: "/Work/Customer_Info",
                data: { Id: parseInt($("#AssignCustomer").val()) },
                ExecSuccess: function (result) { UpdCustomerInfo(result.dataServer); }
            });
        } else {
            UpdCustomerInfo(null);
        }

        $("#AssignOn").datepicker({
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true
        });

        $("#Cost, #Collected").spinner({
            min: 0,
            step: 25,
            numberFormat: "n"
        });

        $("#validation").submit(function () {
            var assign_on = ParseTime(this.AssignOn.value);
            this.AssignOn.value = assign_on != null ? assign_on.toISOString() : null;
            Ajax({
                url: $(this).attr("action"),
                type: "post",
                data: $(this).serialize(),
                ExecSuccess: function (result) {
                    if (result.dataServer.Status == "success") {
                        $.pnotify({
                            title: "Thông báo",
                            text: IsNullOrEmpty(result.dataServer.Message) ? "Chỉnh sửa công việc thành công" : result.dataServer.Message,
                            type: "info",
                            opactity: .8
                        });
                    } else {
                        $.pnotify({
                            title: "Lỗi",
                            text: IsNullOrEmpty(result.dataServer.Message) ? "Chỉnh sửa công việc không thành công" : result.dataServer.Message,
                            type: "error",
                            opacity: .8
                        });
                    }

                    if (!IsNullOrEmpty(result.dataServer.RedirectUrl)) {
                        setTimeout(function(){
                            window.location.href = result.dataServer.RedirectUrl;
                        }, 2000);
                    }
                }
            });
            return false;
        });
    });
</script>
<div class="row-fluid">
    <div class="span12">
        <div class="head">
            <div class="isw-documents"></div>
            <h1>Chỉnh sửa công việc: Mã = @Model.Id</h1>
            <div class="clear"></div>
        </div>
        <div class="block-fluid">
            @using (Html.BeginForm("AddOrUpdate", "Work", FormMethod.Post, new { enctype = "multipart/form-data", @id = "validation" }))
            {
                <div class="warning-area"></div>
                @Html.HiddenFor(m => m.Id)
                @Html.HiddenFor(m => m.CreatedOn)
                @Html.HiddenFor(m => m.IsContinue)
                <div class="row-form">
                    <div class="span2">Nhân viên</div>
                    <div class="span10">
                        @Html.DropDownListFor(x => x.AssignStaff, Model.SLAssignStaff, new { @class = "select2-container" })
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Khách hàng</div>
                    <div class="span10 customer-action">
                        <div class="has-customer">
                            <div>
                                <h6>- Mã: <label id="customer-id"></label></h6>
                                <h6>- Tên: <label id="customer-name"></label></h6>
                                <h6>- Địa chỉ: <label id="customer-addr"></label></h6>
                                <h6>- Điện thoại: <label id="customer-phone"></label></h6>
                            </div>
                            <a rel="search" href="#customer-search">
                                <input type="button" data-id="search" class="btn btn-info" value="Tìm kiếm" />
                            </a>
                            <a rel="new" href="#customer-new">
                                <input type="button" data-id="new" class="btn btn-primary" value="Thêm mới" />
                            </a>
                            <input type="button" data-id="remove" class="btn btn-danger" value="Xóa bỏ" />
                        </div>
                        <div class="has-not-customer">
                            <div>
                                <h6>Chưa xác định khách hàng</h6>
                            </div>
                            <a rel="search" href="#customer-search">
                                <input type="button" data-id="search" class="btn btn-info" value="Tìm kiếm" />
                            </a>
                            <a rel="new" href="#customer-new">
                                <input type="button" data-id="new" class="btn btn-primary" value="Thêm mới" />
                            </a>
                        </div>
                        <div style="display:none;">
                            @Html.HiddenFor(m => m.AssignCustomer)
                            <div id="customer-search" style="width:800px;"></div>
                            <div id="customer-new" style="width:800px;"></div>
                        </div>
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Ngày thực hiện</div>
                    <div class="span10">
                        <input type="text" id="AssignOn" name="AssignOn" value="@string.Format("{0:dd/MM/yyyy}", Model.AssignOn)" />
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Chi phí</div>
                    <div class="span10 spinner-con-cus w-subtract-16px">
                        @Html.TextBoxFor(x => x.Cost, new { })</div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Thu được</div>
                    <div class="span10 spinner-con-cus w-subtract-16px">
                        @Html.TextBoxFor(x => x.Collected, new { })</div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Số hóa đơn</div>
                    <div class="span10">
                        @Html.TextBoxFor(x => x.BillNum, new { })</div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Tình trạng</div>
                    <div class="span10">
                        @Html.DropDownListFor(x => x.Status, Model.SLStatus, new { @class = "select2-container" })</div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Nội dung</div>
                    <div class="span10">
                        @Html.TextAreaFor(x => x.Content, new { @cols = "5", @rows = "5", @style = "50px;" })</div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Ghi chú</div>
                    <div class="span10">
                        @Html.TextAreaFor(x => x.Note, new { @cols = "5", @rows = "5", @style = "50px" })
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Ngày tạo</div>
                    <div class="span10">
                        <input type="text" name="CreatedOn" value="@string.Format("{0:dd/MM/yyyy}", Model.CreatedOn)" disabled="disabled" />
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">Ngày sửa cuối</div>
                    <div class="span10">
                        <input type="text" name="LastUpdatedOn" value="@string.Format("{0:dd/MM/yyyy}", Model.LastUpdatedOn)" disabled="disabled" />
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="row-form">
                    <div class="span2">&nbsp;</div>
                    <div class="span10">
                        <input type="submit" class="btn btn-primary" value="Lưu lại" />
                        <input type="button" class="btn btn-primary" value="Lưu lại & Tạo mới" data-id="save-new" />
                    </div>
                    <div class="clear"></div>
                </div>
            }
        </div>
    </div>
</div>
